//
//  TimerModel.swift
//  TanTan_Kotlin
//
//  Created by EDY on 5/26/25.
//

import SwiftUI

class TimerModel: ObservableObject {
    @Published var timer: Int = 0
    func start() {
        Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
            self.timer += 1
        }
    }
}

struct TimerView: View {
    @StateObject private var model = TimerModel()
    
    var body: some View {
        VStack {
            Text("时间: \(model.timer)")
                .font(.largeTitle)
            Button(action: {
                model.start()
            }){
                Text("开始计时")
                    .padding()
                    .background(Color.green)
                    .foregroundColor(.white)
                    .cornerRadius(10)
            }
        }
    }
}


#Preview {
    TimerView()
}
